<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%pre_admin_information}}".
 *
 * @property string $Info_id
 * @property string $Info_url
 * @property string $Info_time
 * @property string $Info_type
 * @property string $Info_title
 * @property string $Info_content
 * @property integer $status
 * @property string $uid
 */
class PreAdminInformation extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%pre_admin_information}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['Info_url', 'Info_time', 'Info_type', 'Info_title', 'Info_content', 'status', 'uid'], 'required'],
            [['Info_time'], 'safe'],
            [['Info_content'], 'string'],
            [['status', 'uid'], 'integer'],
            [['Info_url'], 'string', 'max' => 100],
            [['Info_type'], 'string', 'max' => 20],
            [['Info_title'], 'string', 'max' => 30],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'Info_id' => '所发布的信息的ID',
            'Info_url' => '发布者的url',
            'Info_time' => '发布者的时间',
            'Info_type' => '信息的类型',
            'Info_title' => '信息的标题',
            'Info_content' => '状态',
            'status' => '发布者的ID',
            'uid' => 'Uid',
        ];
    }
	
		public function getPages($query,$curPage=1,$pageSize=10,$search=null){
		if($search)
			$query=$query->andFilerWhere($search);
		$data['count']=$query->count();
		if(!$data['count']){
			return ['count'=>0,'curPage'=>$curPage,'pageSize'=>$pageSize,'start'=>0,
			'end'=>0,'data'=>[],
			];
		}
		$curPage =(ceil($data['count']/$pageSize)<$curPage)
		?ceil($data['count']/$pageSize):$curPage;
		
		$data['curPage']=$curPage;
		$data['pageSize']=$pageSize;
	    $data['start']=($curPage-1)*$pageSize+1;
		$data['end']=(ceil($data['count']/$pageSize)==$curPage)
		   ?$data['count']:($curPage-1)*$pageSize+$pageSize;
		$data['data']=$query
		              ->offset(($curPage-1)*$pageSize)
					  ->limit($pageSize)
					  ->asArray()
					  ->all();
					  
		return $data;
		
	}
}
